package com.nullpointer.xchatfinal.object;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class HistoryMessage {
	private int unreadNum;
	private ChatType chatType;
	private DetailedMessage detailedMessage;
	private boolean isJoinedRoom = true;

	public boolean isJoinedRoom() {
		return isJoinedRoom;
	}

	public void setJoinedRoom(boolean isJoinedRoom) {
		this.isJoinedRoom = isJoinedRoom;
	}

	public ChatType getChatType() {
		return chatType;
	}

	public void setChatType(ChatType chatType) {
		this.chatType = chatType;
	}

	public DetailedMessage getDetailedMessage() {
		return detailedMessage;
	}

	public void setDetailedMessage(DetailedMessage detailedMessage) {
		this.detailedMessage = detailedMessage;
	}

	public int getUnreadNum() {
		return unreadNum;
	}

	public void setUnreadNum(int unreadNum) {
		this.unreadNum = unreadNum;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static HistoryMessage fromJsonToMessageHistory(String json) {
		return new JSONDeserializer<HistoryMessage>().use(null,
				HistoryMessage.class).deserialize(json);
	}

	public static String toJsonArray(Collection<HistoryMessage> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<HistoryMessage> fromJsonArrayToMessageHistorys(
			String json) {
		return new JSONDeserializer<List<HistoryMessage>>()
				.use(null, ArrayList.class).use("values", HistoryMessage.class)
				.deserialize(json);
	}

}
